package com.sskj.gocoin.mine;


import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hey.lib.HeySpinner;
import com.sskj.common.base.App;
import com.sskj.gocoin.R;
import com.sskj.gocoin.R2;
import com.sskj.gocoin.common.widget.ToolBarLayout;
import com.sskj.gocoin.m.bean.ChargeCoinItemBean;
import com.sskj.gocoin.mine.data.FeedBackType;
import com.sskj.gocoin.utils.ClickUtil;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.gocoin.v.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.Flowable;

/**
 * @author Hey
 * Create at  2019/04/02
 */
public class FeedBackActivity extends BaseActivity<FeedBackPresenter> {


    @BindView(R2.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R2.id.reason)
    EditText reason;
    @BindView(R2.id.et_contact)
    EditText contact;
    @BindView(R2.id.spinner)
    HeySpinner spinner;

    @BindView(R2.id.submit)
    Button submit;

    @Override
    public FeedBackPresenter getPresenter() {
        return new FeedBackPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickLinster(v -> finish());
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_feed_back_n;
    }

    @Override
    public void initData() {
        mPresenter.feedBackType();
        ClickUtil.click(submit, () -> {
            if (TextUtils.isEmpty(reason.getText())) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.fabimineJavaFeedBackActivity1));
                return;
            }
            if (TextUtils.isEmpty(contact.getText())) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.feedback_contact));
                return;
            }
            mPresenter.feedBack(typeId,reason.getText().toString(),contact.getText().toString());
        });
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, FeedBackActivity.class);
        context.startActivity(intent);
    }

    public void submitSuccess() {
        ToastUtil.showShort(App.INSTANCE.getString(R.string.fabimineJavaFeedBackActivity2));
        finish();
    }

    public void onDataSuccess(List<FeedBackType> data) {
        initSpinner(data);
    }

    int typeId;

    private void initSpinner(List<FeedBackType> feedBackTypeList) {
        List<String> data = new ArrayList<>();
        for (FeedBackType bean : feedBackTypeList) {
            data.add(bean.getType_name());
        }
        spinner.attachData(data);
        spinner.setOnSelectListener(position -> {
            typeId = feedBackTypeList.get(position).getId();
        });
        spinner.setSelectIndex(0);
    }
}
